const state = {
  user: {
    isNewUser: true, // 是否为新用户
    totalMoney: 0, //钱包总金额
    count: null,  // 新5 | 旧3   所剩抽奖次数
    bigPrize: true, // 新用户特权前三次抽奖必得一次1.0x元,true   
    cardList: [
      { id: 0, name: "n", category: "牛", count: 0 },
      { id: 1, name: "q", category: "气", count: 0 },
      { id: 2, name: "c", category: "冲", count: 0 },
      { id: 3, name: "t", category: "天", count: 0 },
    ]
  },
  start: {
    page: true,
    window: true
    // window: false
  },
  detailIndex: null
}
const getters = {
  user: (state) => state.user,
  start: (state) => state.start,
  detailIndex: (state) => state.detailIndex
}
const mutations = {
  setUserCount(state, number) {
    state.user.count = number
  },
  setUserTotalMoney(state, money) {
    const currentMoney = state.user.totalMoney + parseFloat(money)
    state.user.totalMoney = parseFloat(currentMoney.toFixed(2))
  },
  setAddUserCount(state, category) {
    for (let i = 0; i < state.user.cardList.length; i++) {
      if (state.user.cardList[i].category === category) {
        state.user.cardList[i].count += 1
        return
      }
    }
  },
  setRemoveUserCount(state, index) {
    if (state.user.cardList[index].count <= 0) return
    state.user.cardList[index].count -= 1
  },
  setBigPrize(state) {
    state.user.bigPrize = false
  },
  //提现后钱包的总金额
  setUserSubTotalMoney(state, money) {
    state.user.totalMoney -= money
  },
  setStartPage(state, flag) {
    state.start.page = flag
  },
  setStartWindow(state, flag) {
    state.start.window = flag
  },
  setDetailIndex(state, index) {
    state.detailIndex = index
  }
}
const actions = {}

const activity = {
  namespaced: true, state, getters, actions, mutations
}
export default activity